home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / linked.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  29KB  |  911 lines

  1. /***********************************************************************/
  2. /* LINKED.C - Linked list routines.                                    */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1995 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 5314
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38.  
  39. /*
  40. $Id: linked.c 2.0 1995/01/26 16:31:19 MH Release MH $
  41. */
  42.  
  43. #include <stdio.h>
  44. #include "the.h"
  45. #include "proto.h"
  46. /*-------------------------- external data ----------------------------*/
  47. /***********************************************************************/
  48. #ifdef PROTO
  49. LINE *lll_add(LINE *first,LINE *curr,unsigned short size)
  50. #else
  51. LINE *lll_add(first,curr,size)
  52. LINE *first;
  53. LINE *curr;
  54. unsigned short size;
  55. #endif
  56. /***********************************************************************/
  57. /* Adds a LINE to the current linked list after the current member.    */
  58. /* PARAMETERS:                                                         */
  59. /* first      - pointer to first LINE in linked list                   */
  60. /* curr       - pointer to current LINE in linked list                 */
  61. /* size       - size of a LINE item                                    */
  62. /* RETURN:    - pointer to next LINE item                              */
  63. /***********************************************************************/
  64. {
  65. /*--------------------------- local data ------------------------------*/
  66.  LINE *next=NULL;
  67. /*--------------------------- processing ------------------------------*/
  68. #ifdef TRACE
  69.  trace_function("linked.c:    lll_add");
  70. #endif
  71.  
  72.  if ((next=(LINE *)(*the_malloc)(size)) != (LINE *)NULL)
  73.    {
  74.     if (curr == NULL)
  75.       {
  76.        first = next;
  77.        next->next = NULL;
  78.       }
  79.     else
  80.       {
  81.        if (curr->next != NULL)
  82.           curr->next->prev = next;
  83.        next->next = curr->next;
  84.        curr->next = next;
  85.       }
  86.     next->prev = curr;
  87.    }
  88. /*---------------------------------------------------------------------*/
  89. /* Ensure all pointers in the structure are set to NULL                */
  90. /*---------------------------------------------------------------------*/
  91.  next->line = NULL;
  92.  next->name = NULL;
  93.  next->pre = NULL;
  94. #ifdef TRACE
  95.  trace_return();
  96. #endif
  97.  return(next);
  98. }
  99. /***********************************************************************/
  100. #ifdef PROTO
  101. LINE *lll_del(LINE **first,LINE **last,LINE *curr,short direction)
  102. #else
  103. LINE *lll_del(first,last,curr,direction)
  104. LINE **first;
  105. LINE **last;
  106. LINE *curr;
  107. short direction;
  108. #endif
  109. /***********************************************************************/
  110. {
  111. /*--------------------------- local data ------------------------------*/
  112.  LINE *new_curr=NULL;
  113. /*--------------------------- processing ------------------------------*/
  114. #ifdef TRACE
  115.  trace_function("linked.c:    lll_del");
  116. #endif
  117. /*---------------------------------------------------------------------*/
  118. /* Delete the only record                                              */
  119. /*---------------------------------------------------------------------*/
  120.  if (curr->prev == NULL && curr->next == NULL)
  121.    {
  122.     (*the_free)(curr);
  123.     *first = NULL;
  124.     if (last != NULL)
  125.        *last = NULL;
  126. #ifdef TRACE
  127.     trace_return();
  128. #endif
  129.     return(NULL);
  130.    }
  131. /*---------------------------------------------------------------------*/
  132. /* Delete the first record                                             */
  133. /*---------------------------------------------------------------------*/
  134.  if (curr->prev == NULL)
  135.    {
  136.     curr->next->prev = NULL;
  137.     *first = new_curr = curr->next;
  138.     (*the_free)(curr);
  139.     curr = new_curr;
  140. #ifdef TRACE
  141.     trace_return();
  142. #endif
  143.     return(curr);
  144.    }
  145. /*---------------------------------------------------------------------*/
  146. /* Delete the last  record                                             */
  147. /*---------------------------------------------------------------------*/
  148.  if (curr->next == NULL)
  149.    {
  150.     curr->prev->next = NULL;
  151.     new_curr = curr->prev;
  152.     if (last != NULL)
  153.        *last = curr->prev;
  154.     (*the_free)(curr);
  155.     curr = new_curr;
  156. #ifdef TRACE
  157.     trace_return();
  158. #endif
  159.     return(curr);
  160.    }
  161. /*---------------------------------------------------------------------*/
  162. /* All others                                                          */
  163. /*---------------------------------------------------------------------*/
  164.  curr->prev->next = curr->next;
  165.  curr->next->prev = curr->prev;
  166.  if (direction == DIRECTION_FORWARD)
  167.     new_curr = curr->next;
  168.  else
  169.    new_curr = curr->prev;
  170.  
  171.  (*the_free)(curr);
  172.  curr = new_curr;
  173. #ifdef TRACE
  174.  trace_return();
  175. #endif
  176.  return(curr);
  177. }
  178. /***********************************************************************/
  179. #ifdef PROTO
  180. LINE *lll_free(LINE *first)
  181. #else
  182. LINE *lll_free(first)
  183. LINE *first;
  184. #endif
  185. /***********************************************************************/
  186. /* Free up all allocated memory until the last item in the linked-list */
  187. /* PARAMETERS:                                                         */
  188. /* first      - pointer to first line for the file                     */
  189. /* RETURN:    - NULL                                                   */
  190. /***********************************************************************/
  191. {
  192. /*--------------------------- local data ------------------------------*/
  193.  LINE *curr=NULL;
  194.  LINE *new_curr=NULL;
  195. /*--------------------------- processing ------------------------------*/
  196. #ifdef TRACE
  197.  trace_function("linked.c:    lll_free");
  198. #endif
  199.  curr = first;
  200.  while (curr != NULL)
  201.    {
  202.     (*the_free)(curr->line);
  203.     if (curr->name != (CHARTYPE *)NULL)
  204.        (*the_free)(curr->name);
  205.     new_curr = curr->next;
  206.     (*the_free)(curr);
  207.     curr = new_curr;
  208.    }
  209. #ifdef TRACE
  210.  trace_return();
  211. #endif
  212.  return((LINE *)NULL);
  213. }
  214. /***********************************************************************/
  215. #ifdef PROTO
  216. LINE *lll_find(LINE *first,LINETYPE row)
  217. #else
  218. LINE *lll_find(first,row)
  219. LINE *first;
  220. LINETYPE row;
  221. #endif
  222. /***********************************************************************/
  223. {
  224. /*--------------------------- local data ------------------------------*/
  225.  LINE *curr=NULL;
  226.  LINETYPE i=0L;
  227. /*--------------------------- processing ------------------------------*/
  228. #ifdef TRACE
  229.  trace_function("linked.c:    lll_find");
  230. #endif
  231.  curr = first;
  232.  if (curr != NULL)
  233.     for(i=0L;i<row && curr->next != NULL; i++, curr=curr->next);
  234. #ifdef TRACE
  235.  trace_return();
  236. #endif
  237.  return(curr);
  238. }
  239. /***********************************************************************/
  240. #ifdef PROTO
  241. VIEW_DETAILS *vll_add(VIEW_DETAILS *first,VIEW_DETAILS *curr,unsigned short size)
  242. #else
  243. VIEW_DETAILS *vll_add(first,curr,size)
  244. VIEW_DETAILS *first;
  245. VIEW_DETAILS *curr;
  246. unsigned short size;
  247. #endif
  248. /***********************************************************************/
  249. /* Adds a VIEW_DETAILS to the current linked list after the current member.    */
  250. /* PARAMETERS:                                                         */
  251. /* first      - pointer to first VIEW_DETAILS in linked list                   */
  252. /* curr       - pointer to current VIEW_DETAILS in linked list                 */
  253. /* size       - size of a VIEW_DETAILS item                                    */
  254. /* RETURN:    - pointer to next VIEW_DETAILS item                              */
  255. /***********************************************************************/
  256. {
  257. /*--------------------------- local data ------------------------------*/
  258.  VIEW_DETAILS *next=(VIEW_DETAILS *)NULL;
  259. /*--------------------------- processing ------------------------------*/
  260. #ifdef TRACE
  261.  trace_function("linked.c:    vll_add");
  262. #endif
  263.  
  264.  if ((next=(VIEW_DETAILS *)(*the_malloc)(size)) != (VIEW_DETAILS *)NULL)
  265.    {
  266.     if (curr == (VIEW_DETAILS *)NULL)
  267.       {
  268.        first = next;
  269.        next->next = (VIEW_DETAILS *)NULL;
  270.       }
  271.     else
  272.       {
  273.        if (curr->next != (VIEW_DETAILS *)NULL)
  274.           curr->next->prev = next;
  275.        next->next = curr->next;
  276.        curr->next = next;
  277.       }
  278.     next->prev = curr;
  279.    }
  280. /*---------------------------------------------------------------------*/
  281. /* Ensure all pointers in the structure are set to NULL                */
  282. /*---------------------------------------------------------------------*/
  283.  next->file_for_view == NULL;
  284. #ifdef TRACE
  285.  trace_return();
  286. #endif
  287.  return(next);
  288. }
  289. /***********************************************************************/
  290. #ifdef PROTO
  291. VIEW_DETAILS *vll_del(VIEW_DETAILS **first,VIEW_DETAILS **last,VIEW_DETAILS *curr,short direction)
  292. #else
  293. VIEW_DETAILS *vll_del(first,last,curr,direction)
  294. VIEW_DETAILS **first;
  295. VIEW_DETAILS **last;
  296. VIEW_DETAILS *curr;
  297. short direction;
  298. #endif
  299. /***********************************************************************/
  300. {
  301. /*--------------------------- local data ------------------------------*/
  302.  VIEW_DETAILS *new_curr=NULL;
  303. /*--------------------------- processing ------------------------------*/
  304. #ifdef TRACE
  305.  trace_function("linked.c:    vll_del");
  306. #endif
  307. /*---------------------------------------------------------------------*/
  308. /* Delete the only record                                              */
  309. /*---------------------------------------------------------------------*/
  310.  if (curr->prev == NULL && curr->next == NULL)
  311.    {
  312.     (*the_free)(curr);
  313. #ifdef TRACE
  314.     trace_return();
  315. #endif
  316.     *first = curr = NULL;
  317.     if (last != NULL)
  318.        *last = NULL;
  319.     return(NULL);
  320.    }
  321. /*---------------------------------------------------------------------*/
  322. /* Delete the first record                                             */
  323. /*---------------------------------------------------------------------*/
  324.  if (curr->prev == NULL)
  325.    {
  326.     curr->next->prev = NULL;
  327.     *first = new_curr = curr->next;
  328.     (*the_free)(curr);
  329.     curr = new_curr;
  330. #ifdef TRACE
  331.     trace_return();
  332. #endif
  333.     return(curr);
  334.    }
  335. /*---------------------------------------------------------------------*/
  336. /* Delete the last  record                                             */
  337. /*---------------------------------------------------------------------*/
  338.  if (curr->next == NULL)
  339.    {
  340.     curr->prev->next = NULL;
  341.     new_curr = curr->prev;
  342.     if (last != NULL)
  343.        *last = curr->prev;
  344.     (*the_free)(curr);
  345.     curr = new_curr;
  346. #ifdef TRACE
  347.     trace_return();
  348. #endif
  349.     return(curr);
  350.    }
  351. /*---------------------------------------------------------------------*/
  352. /* All others                                                          */
  353. /*---------------------------------------------------------------------*/
  354.  curr->prev->next = curr->next;
  355.  curr->next->prev = curr->prev;
  356.  if (direction == DIRECTION_FORWARD)
  357.    new_curr = curr->next;
  358.  else
  359.    new_curr = curr->prev;
  360.  
  361.  (*the_free)(curr);
  362.  curr = new_curr;
  363. #ifdef TRACE
  364.  trace_return();
  365. #endif
  366.  return(curr);
  367. }
  368. /***********************************************************************/
  369. #ifdef PROTO
  370. DEFINE *dll_add(DEFINE *first,DEFINE *curr,unsigned short size)
  371. #else
  372. DEFINE *dll_add(first,curr,size)
  373. DEFINE *first;
  374. DEFINE *curr;
  375. unsigned short size;
  376. #endif
  377. /***********************************************************************/
  378. /* Adds a DEFINE to the current linked list after the current member.  */
  379. /* PARAMETERS:                                                         */
  380. /* first      - pointer to first DEFINE in linked list                 */
  381. /* curr       - pointer to current DEFINE in linked list               */
  382. /* size       - size of a DEFINE item                                  */
  383. /* RETURN:    - pointer to next DEFINE item                            */
  384. /***********************************************************************/
  385. {
  386. /*--------------------------- local data ------------------------------*/
  387.  DEFINE *next=NULL;
  388. /*--------------------------- processing ------------------------------*/
  389. #ifdef TRACE
  390.  trace_function("linked.c:    dll_add");
  391. #endif
  392.  if ((next=(DEFINE *)(*the_malloc)(size)) != (DEFINE *)NULL)
  393.    {
  394.     if (curr == NULL)
  395.       {
  396.        first = next;
  397.        next->next = NULL;
  398.       }
  399.     else
  400.       {
  401.        if (curr->next != NULL)
  402.           curr->next->prev = next;
  403.        next->next = curr->next;
  404.        curr->next = next;
  405.       }
  406.     next->prev = curr;
  407.    }
  408. /*---------------------------------------------------------------------*/
  409. /* Ensure all pointers in the structure are set to NULL                */
  410. /*---------------------------------------------------------------------*/
  411.  next->def_params = NULL;
  412. #ifdef TRACE
  413.  trace_return();
  414. #endif
  415.  return(next);
  416. }
  417. /***********************************************************************/
  418. #ifdef PROTO
  419. DEFINE *dll_del(DEFINE **first,DEFINE **last,DEFINE *curr,short direction)
  420. #else
  421. DEFINE *dll_del(first,last,curr,direction)
  422. DEFINE **first;
  423. DEFINE **last;
  424. DEFINE *curr;
  425. short direction;
  426. #endif
  427. /***********************************************************************/
  428. {
  429. /*--------------------------- local data ------------------------------*/
  430.  DEFINE *new_curr=NULL;
  431. /*--------------------------- processing ------------------------------*/
  432. #ifdef TRACE
  433.  trace_function("linked.c:    dll_del");
  434. #endif
  435. /*---------------------------------------------------------------------*/
  436. /* Delete the only record                                              */
  437. /*---------------------------------------------------------------------*/
  438.  if (curr->prev == NULL && curr->next == NULL)
  439.    {
  440.     (*the_free)(curr);
  441.     *first = NULL;
  442.     if (last != NULL)
  443.        *last = NULL;
  444. #ifdef TRACE
  445.     trace_return();
  446. #endif
  447.     return(NULL);
  448.    }
  449. /*---------------------------------------------------------------------*/
  450. /* Delete the first record                                             */
  451. /*---------------------------------------------------------------------*/
  452.  if (curr->prev == NULL)
  453.    {
  454.     curr->next->prev = NULL;
  455.     *first = new_curr = curr->next;
  456.     (*the_free)(curr);
  457.     curr = new_curr;
  458. #ifdef TRACE
  459.     trace_return();
  460. #endif
  461.     return(curr);
  462.    }
  463. /*---------------------------------------------------------------------*/
  464. /* Delete the last  record                                             */
  465. /*---------------------------------------------------------------------*/
  466.  if (curr->next == NULL)
  467.    {
  468.     curr->prev->next = NULL;
  469.     new_curr = curr->prev;
  470.     if (last != NULL)
  471.        *last = curr->prev;
  472.     (*the_free)(curr);
  473.     curr = new_curr;
  474. #ifdef TRACE
  475.     trace_return();
  476. #endif
  477.     return(curr);
  478.    }
  479. /*---------------------------------------------------------------------*/
  480. /* All others                                                          */
  481. /*---------------------------------------------------------------------*/
  482.  curr->prev->next = curr->next;
  483.  curr->next->prev = curr->prev;
  484.  if (direction == DIRECTION_FORWARD)
  485.    new_curr = curr->next;
  486.  else
  487.    new_curr = curr->prev;
  488.  
  489.  (*the_free)(curr);
  490.  curr = new_curr;
  491. #ifdef TRACE
  492.  trace_return();
  493. #endif
  494.  return(curr);
  495. }
  496. /***********************************************************************/
  497. #ifdef PROTO
  498. DEFINE *dll_free(DEFINE *first)
  499. #else
  500. DEFINE *dll_free(first)
  501. DEFINE *first;
  502. #endif
  503. /***********************************************************************/
  504. {
  505. /*--------------------------- local data ------------------------------*/
  506.  DEFINE *curr=NULL;
  507.  DEFINE *new_curr=NULL;
  508. /*--------------------------- processing ------------------------------*/
  509. #ifdef TRACE
  510.  trace_function("linked.c:    dll_free");
  511. #endif
  512.  curr = first;
  513.  while (curr != (DEFINE *)NULL)
  514.    {
  515.     if (curr->def_params != NULL)
  516.        (*the_free)(curr->def_params);
  517.     new_curr = curr->next;
  518.     (*the_free)(curr);
  519.     curr = new_curr;
  520.    }
  521. #ifdef TRACE
  522.  trace_return();
  523. #endif
  524.  return((DEFINE *)NULL);
  525. }
  526. /***********************************************************************/
  527. #ifdef PROTO
  528. PPC *pll_add(PPC *first,PPC *curr,unsigned short size)
  529. #else
  530. PPC *pll_add(first,curr,size)
  531. PPC *first;
  532. PPC *curr;
  533. unsigned short size;
  534. #endif
  535. /***********************************************************************/
  536. /* Adds a PPC to the current linked list after the current member.     */
  537. /* PARAMETERS:                                                         */
  538. /* first      - pointer to first PPC in linked list                    */
  539. /* curr       - pointer to current PPC in linked list                  */
  540. /* size       - size of a PPC item                                     */
  541. /* RETURN:    - pointer to next PPC item                               */
  542. /***********************************************************************/
  543. {
  544. /*--------------------------- local data ------------------------------*/
  545.  PPC *next=NULL;
  546. /*--------------------------- processing ------------------------------*/
  547. #ifdef TRACE
  548.  trace_function("linked.c:    pll_add");
  549. #endif
  550.  
  551.  if ((next=(PPC *)(*the_malloc)(size)) != (PPC *)NULL)
  552.    {
  553.     if (curr == NULL)
  554.       {
  555.        first = next;
  556.        next->next = NULL;
  557.       }
  558.     else
  559.       {
  560.        if (curr->next != NULL)
  561.           curr->next->prev = next;
  562.        next->next = curr->next;
  563.        curr->next = next;
  564.       }
  565.     next->prev = curr;
  566.    }
  567. /*---------------------------------------------------------------------*/
  568. /* Ensure all pointers in the structure are set to NULL                */
  569. /*---------------------------------------------------------------------*/
  570. #ifdef TRACE
  571.  trace_return();
  572. #endif
  573.  return(next);
  574. }
  575. /***********************************************************************/
  576. #ifdef PROTO
  577. PPC *pll_del(PPC **first,PPC **last,PPC *curr,short direction)
  578. #else
  579. PPC *pll_del(first,last,curr,direction)
  580. PPC **first;
  581. PPC **last;
  582. PPC *curr;
  583. short direction;
  584. #endif
  585. /***********************************************************************/
  586. {
  587. /*--------------------------- local data ------------------------------*/
  588.  PPC *new_curr=NULL;
  589. /*--------------------------- processing ------------------------------*/
  590. #ifdef TRACE
  591.  trace_function("linked.c:    pll_del");
  592. #endif
  593. /*---------------------------------------------------------------------*/
  594. /* Delete the only record                                              */
  595. /*---------------------------------------------------------------------*/
  596.  if (curr->prev == NULL && curr->next == NULL)
  597.    {
  598.     (*the_free)(curr);
  599.     *first = NULL;
  600.     if (last != NULL)
  601.        *last = NULL;
  602. #ifdef TRACE
  603.     trace_return();
  604. #endif
  605.     return(NULL);
  606.    }
  607. /*---------------------------------------------------------------------*/
  608. /* Delete the first record                                             */
  609. /*---------------------------------------------------------------------*/
  610.  if (curr->prev == NULL)
  611.    {
  612.     curr->next->prev = NULL;
  613.     *first = new_curr = curr->next;
  614.     (*the_free)(curr);
  615.     curr = new_curr;
  616. #ifdef TRACE
  617.     trace_return();
  618. #endif
  619.     return(curr);
  620.    }
  621. /*---------------------------------------------------------------------*/
  622. /* Delete the last  record                                             */
  623. /*---------------------------------------------------------------------*/
  624.  if (curr->next == NULL)
  625.    {
  626.     curr->prev->next = NULL;
  627.     new_curr = curr->prev;
  628.     if (last != NULL)
  629.        *last = curr->prev;
  630.     (*the_free)(curr);
  631.     curr = new_curr;
  632. #ifdef TRACE
  633.     trace_return();
  634. #endif
  635.     return(curr);
  636.    }
  637. /*---------------------------------------------------------------------*/
  638. /* All others                                                          */
  639. /*---------------------------------------------------------------------*/
  640.  curr->prev->next = curr->next;
  641.  curr->next->prev = curr->prev;
  642.  if (direction == DIRECTION_FORWARD)
  643.    new_curr = curr->next;
  644.  else
  645.    new_curr = curr->prev;
  646.  
  647.  (*the_free)(curr);
  648.  curr = new_curr;
  649. #ifdef TRACE
  650.  trace_return();
  651. #endif
  652.  return(curr);
  653. }
  654. /***********************************************************************/
  655. #ifdef PROTO
  656. PPC *pll_free(PPC *first)
  657. #else
  658. PPC *pll_free(first)
  659. PPC *first;
  660. #endif
  661. /***********************************************************************/
  662. /* Free up all allocated memory until the last item in the linked-list */
  663. /* PARAMETERS:                                                         */
  664. /* first      - pointer to first line for the file                     */
  665. /* RETURN:    - NULL                                                   */
  666. /***********************************************************************/
  667. {
  668. /*--------------------------- local data ------------------------------*/
  669.  PPC *curr=NULL;
  670.  PPC *new_curr=NULL;
  671. /*--------------------------- processing ------------------------------*/
  672. #ifdef TRACE
  673.  trace_function("linked.c:    pll_free");
  674. #endif
  675.  curr = first;
  676.  while (curr != NULL)
  677.    {
  678.     new_curr = curr->next;
  679.     (*the_free)(curr);
  680.     curr = new_curr;
  681.    }
  682. #ifdef TRACE
  683.  trace_return();
  684. #endif
  685.  return((PPC *)NULL);
  686. }
  687. /***********************************************************************/
  688. #ifdef PROTO
  689. PPC *pll_find(PPC *first,LINETYPE line_number)
  690. #else
  691. PPC *pll_find(first,line_number)
  692. PPC *first;
  693. LINETYPE line_number;
  694. #endif
  695. /***********************************************************************/
  696. {
  697. /*--------------------------- local data ------------------------------*/
  698.  PPC *curr_ppc=NULL;
  699. /*--------------------------- processing ------------------------------*/
  700. #ifdef TRACE
  701.  trace_function("linked.c:    pll_find");
  702. #endif
  703.  curr_ppc = first;
  704.  while (curr_ppc != NULL)
  705.    {
  706.     if (curr_ppc->ppc_line_number == line_number)
  707.       {
  708. #ifdef TRACE
  709.        trace_return();
  710. #endif
  711.        return(curr_ppc);
  712.       }
  713.     curr_ppc = curr_ppc->next;
  714.    }
  715. #ifdef TRACE
  716.  trace_return();
  717. #endif
  718.  return(NULL);
  719. }
  720. /***********************************************************************/
  721. #ifdef PROTO
  722. RESERVED *rll_add(RESERVED *first,RESERVED *curr,unsigned short size)
  723. #else
  724. RESERVED *rll_add(first,curr,size)
  725. RESERVED *first;
  726. RESERVED *curr;
  727. unsigned short size;
  728. #endif
  729. /***********************************************************************/
  730. /* Adds a RESERVED to the current linked list after the current member.    */
  731. /* PARAMETERS:                                                         */
  732. /* first      - pointer to first RESERVED in linked list                   */
  733. /* curr       - pointer to current RESERVED in linked list                 */
  734. /* size       - size of a RESERVED item                                    */
  735. /* RETURN:    - pointer to next RESERVED item                              */
  736. /***********************************************************************/
  737. {
  738. /*--------------------------- local data ------------------------------*/
  739.  RESERVED *next=NULL;
  740. /*--------------------------- processing ------------------------------*/
  741. #ifdef TRACE
  742.  trace_function("linked.c:    rll_add");
  743. #endif
  744.  
  745.  if ((next=(RESERVED *)(*the_malloc)(size)) != (RESERVED *)NULL)
  746.    {
  747.     if (curr == NULL)
  748.       {
  749.        first = next;
  750.        next->next = NULL;
  751.       }
  752.     else
  753.       {
  754.        if (curr->next != NULL)
  755.           curr->next->prev = next;
  756.        next->next = curr->next;
  757.        curr->next = next;
  758.       }
  759.     next->prev = curr;
  760.    }
  761. /*---------------------------------------------------------------------*/
  762. /* Ensure all pointers in the structure are set to NULL                */
  763. /*---------------------------------------------------------------------*/
  764.  next->line = NULL;
  765.  next->spec = NULL;
  766. #ifdef TRACE
  767.  trace_return();
  768. #endif
  769.  return(next);
  770. }
  771. /***********************************************************************/
  772. #ifdef PROTO
  773. RESERVED *rll_del(RESERVED **first,RESERVED **last,RESERVED *curr,short direction)
  774. #else
  775. RESERVED *rll_del(first,last,curr,direction)
  776. RESERVED **first;
  777. RESERVED **last;
  778. RESERVED *curr;
  779. short direction;
  780. #endif
  781. /***********************************************************************/
  782. {
  783. /*--------------------------- local data ------------------------------*/
  784.  RESERVED *new_curr=NULL;
  785. /*--------------------------- processing ------------------------------*/
  786. #ifdef TRACE
  787.  trace_function("linked.c:    rll_del");
  788. #endif
  789. /*---------------------------------------------------------------------*/
  790. /* Delete the only record                                              */
  791. /*---------------------------------------------------------------------*/
  792.  if (curr->prev == NULL && curr->next == NULL)
  793.    {
  794.     (*the_free)(curr);
  795.     *first = NULL;
  796.     if (last != NULL)
  797.        *last = NULL;
  798. #ifdef TRACE
  799.     trace_return();
  800. #endif
  801.     return(NULL);
  802.    }
  803. /*---------------------------------------------------------------------*/
  804. /* Delete the first record                                             */
  805. /*---------------------------------------------------------------------*/
  806.  if (curr->prev == NULL)
  807.    {
  808.     curr->next->prev = NULL;
  809.     *first = new_curr = curr->next;
  810.     (*the_free)(curr);
  811.     curr = new_curr;
  812. #ifdef TRACE
  813.     trace_return();
  814. #endif
  815.     return(curr);
  816.    }
  817. /*---------------------------------------------------------------------*/
  818. /* Delete the last  record                                             */
  819. /*---------------------------------------------------------------------*/
  820.  if (curr->next == NULL)
  821.    {
  822.     curr->prev->next = NULL;
  823.     new_curr = curr->prev;
  824.     if (last != NULL)
  825.        *last = curr->prev;
  826.     (*the_free)(curr);
  827.     curr = new_curr;
  828. #ifdef TRACE
  829.     trace_return();
  830. #endif
  831.     return(curr);
  832.    }
  833. /*---------------------------------------------------------------------*/
  834. /* All others                                                          */
  835. /*---------------------------------------------------------------------*/
  836.  curr->prev->next = curr->next;
  837.  curr->next->prev = curr->prev;
  838.  if (direction == DIRECTION_FORWARD)
  839.    new_curr = curr->next;
  840.  else
  841.    new_curr = curr->prev;
  842.  
  843.  (*the_free)(curr);
  844.  curr = new_curr;
  845. #ifdef TRACE
  846.  trace_return();
  847. #endif
  848.  return(curr);
  849. }
  850. /***********************************************************************/
  851. #ifdef PROTO
  852. RESERVED *rll_free(RESERVED *first)
  853. #else
  854. RESERVED *rll_free(first)
  855. RESERVED *first;
  856. #endif
  857. /***********************************************************************/
  858. /* Free up all allocated memory until the last item in the linked-list */
  859. /* PARAMETERS:                                                         */
  860. /* first      - pointer to first line for the file                     */
  861. /* RETURN:    - NULL                                                   */
  862. /***********************************************************************/
  863. {
  864. /*--------------------------- local data ------------------------------*/
  865.  RESERVED *curr=NULL;
  866.  RESERVED *new_curr=NULL;
  867. /*--------------------------- processing ------------------------------*/
  868. #ifdef TRACE
  869.  trace_function("linked.c:    rll_free");
  870. #endif
  871.  curr = first;
  872.  while (curr != NULL)
  873.    {
  874.     (*the_free)(curr->line);
  875.     if (curr->spec != (CHARTYPE *)NULL)
  876.        (*the_free)(curr->spec);
  877.     new_curr = curr->next;
  878.     (*the_free)(curr);
  879.     curr = new_curr;
  880.    }
  881. #ifdef TRACE
  882.  trace_return();
  883. #endif
  884.  return((RESERVED *)NULL);
  885. }
  886. /***********************************************************************/
  887. #ifdef PROTO
  888. RESERVED *rll_find(RESERVED *first,short row)
  889. #else
  890. RESERVED *rll_find(first,row)
  891. RESERVED *first;
  892. short row;
  893. #endif
  894. /***********************************************************************/
  895. {
  896. /*--------------------------- local data ------------------------------*/
  897.  RESERVED *curr=NULL;
  898.  short i=0;
  899. /*--------------------------- processing ------------------------------*/
  900. #ifdef TRACE
  901.  trace_function("linked.c:    rll_find");
  902. #endif
  903.  curr = first;
  904.  if (curr != NULL)
  905.     for(i=0;i<row && curr->next != NULL; i++, curr=curr->next);
  906. #ifdef TRACE
  907.  trace_return();
  908. #endif
  909.  return(curr);
  910. }
  911.